package com.qfedu.fmmall.config;

import com.qfedu.fmmall.interceptor.TokenHeand;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 解决前后端跨域问题
 */
@Configuration
public class WebMvcConfigurerHeand implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*").
                allowCredentials(true).allowedMethods("*").allowedHeaders("*");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println(1);
        registry.addInterceptor(new TokenHeand()).addPathPatterns("/shopcart/**").
                addPathPatterns("/orders/**").addPathPatterns("/useraddr/**").
                excludePathPatterns("/user/**");

    }
}
